package com.cbwl.eoas.common.web;

import java.io.Serializable;

import com.cbwl.eoas.common.file.ExceptionPropertiesUtil;

/**
 * Ajax处理结果对象
 *
 * @author yyb
 * @param <T>
 * @date 2014年3月7日下午4:08:52
 */
public class Result implements Serializable
{
	/**
	 * @fields serialVersionUID
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * @fields status 状态信息，正确返回OK，否则返回 ERROR，如果返回ERROR则需要填写Message信息
	 */
	private Status status;
	/**
	 * @fields record 消息对象
	 */
	private String message;
	/**
	 * 数据对象
	 */
	private Object data;

	/**
	 * 返回码
	 */
	private String code;

	public Result()
	{
		super();
	}

	/**
	 * @description
	 * @param status
	 *            状态
	 * @param message
	 *            消息
	 */
	public Result(Status status, String message)
	{
		this.status = status;
		this.message = message;
	}
	
	
	/**
	 * @description
	 * @param status
	 *            状态
	 * @param message
	 *            消息
	 */
	public Result(Status status, String message, String code)
	{
		this.status = status;
		this.message = message;
		this.code = code;
	}

	/**
	 * @description
	 * @param status
	 *            状态
	 * @param message
	 *            消息
	 */
	public Result(Status status, String message, Object data)
	{
		this.status = status;
		this.message = message;
		this.data = data;
	}

	/**
	 * 结果类型信息
	 *
	 * @author zhouyang
	 * @date 2014年3月7日下午4:20:23
	 */
	public enum Status
	{
		OK, ERROR
	}

	/**
	 * 添加成功结果信息
	 *
	 * @param record
	 */
	public void addOK(String message)
	{
		this.message = message;
		this.status = Status.OK;
		this.code = "8200";
	}

	/**
	 * 添加成功结果信息
	 *
	 * @param record
	 */
	public void addOK(String message, Object data)
	{
		this.message = message;
		this.data = data;
		this.status = Status.OK;
		this.code = "8200";
	}

	public void addOK(Object data)
	{
		this.data = data;
		this.status = Status.OK;
		this.code = "8200";
	}

	/**
	 * 添加错误消息
	 *
	 * @param message
	 */
	public void addError(String message)
	{
		this.message = message;
		this.status = Status.ERROR;
		this.code = "8300";
	}

	public Status getStatus()
	{
		return status;
	}

	public void setStatus(Status status)
	{
		this.status = status;
	}

	public Object getMessage()
	{
		return message;
	}

	public void setMessage(String message)
	{
		this.message = message;
	}

	public Object getData()
	{
		return data;
	}

	public void setData(Object data)
	{
		this.data = data;
	}

	public String getCode()
	{
		return code;
	}

	public void setCode(String code)
	{
		this.code = code;
		this.message=ExceptionPropertiesUtil.getExceptionDesc(code);
	}

	@Override
	public String toString() {
		return super.toString();
	}

	
	
	
}
